using System;
using SpecMaker.Core.Exceptions;

namespace SpecMaker.Core.Assertions
{
    public static class AssertionExtensions
    {
        public static void ShouldEqual(this object actual, object expected)
        {
            if (!actual.Equals(expected))
                throw new RuleException(string.Format("The expected value of {0} was actually {1}.", actual, expected));
        }
       
        public static void ShouldNotEqual(this object actual, object expected)
        {
            if (actual.Equals(expected))
                throw new RuleException(string.Format("The two values incorrectly equal one another. The number was {0}", expected));
        }
        public static void ShouldStartWith(this string actual, string expected)
        {
            if (!actual.StartsWith(expected))
                throw new RuleException(string.Format("The actual starting value is different than the expected text. The expected text was {1} and the actual text is {0}", actual, expected));
        }
        public static void ShouldContain(this string actual, string expected)
        {
            if(!actual.Contains(expected))
                throw new RuleException(string.Format("The actual containing text value is different than the expected text. The expected text of {0} was not found",expected));
        }

        public static void ShouldEndWith(this string string1, string string2)
        {
            if (!string1.EndsWith(string2))
                throw new RuleException(string.Format("The actual ending text value is different than the expected text. The expected text of {0} was not found", string2));
        }

        public static void DoubleIsEqualWithTolerance(this double a, double b, double tolerance)
        {
            var val = (Math.Abs(a - b) < tolerance) ? 1 : 0;
           if(val == 0)
            throw new RuleException(string.Format("The two double numbers were not equal within a tolerable level of {0}.",tolerance));
        }
       
    }
}